var t = require("../../@babel/runtime/helpers/defineProperty"),
  a = require("../../res/www.a9a.cn.js"),
  e = getApp(),
  i = wx.getStorageSync("COOK_U"),
  s = 1,
  n = !0;
Page({
  data: { triggered: !0, mask_class: "alpha0_100", scrolltop: 99999 },
  onLoad: function (t) {
    var n = this;
    (s = 1),
      e.get_openid().then(function (s) {
        n.setData({
          uid: t.uid,
          color: e._ZEAI.color,
          rgbcolor: a.c16_rgb(e._ZEAI.color),
          loveb_str: e._ZEAI.loveb,
        }),
          e.chklogin().then(function (t) {
            t
              ? ((i = wx.getStorageSync("COOK_U")),
                e.ajax({
                  url: "chat.php",
                  data: { submitok: "chat", uid: n.data.uid, openid: i.openid },
                  success: function (t) {
                    1 == t.flag
                      ? (n.setData({ U: t.U, MY: t.MY }),
                        wx.setNavigationBarTitle({ title: t.U.nickname }),
                        n.init_list())
                      : "nosign" == t.flag
                      ? wx.showModal({
                          title: t.title,
                          content: t.msg,
                          confirmColor: n.data.color,
                          cancelText: "取消",
                          confirmText: "立即签署",
                          success: function (t) {
                            t.confirm
                              ? wx.redirectTo({ url: "/pages/my/sign" })
                              : wx.navigateBack();
                          },
                        })
                      : ((t.this = n), a.sorry(t));
                  },
                }),
                (n.time = setInterval(function () {
                  n.chk_flag();
                }, 5e3)))
              : wx.reLaunch({ url: "../index/index" });
          });
      });
  },
  init_list: function () {
    var a = this;
    wx.showLoading({ title: "玩命加载中", mask: !0 }),
      (n = !1),
      (i = wx.getStorageSync("COOK_U")),
      e.ajax({
        url: "chat.php",
        data: { submitok: "init_list", uid: a.data.uid, openid: i.openid },
        success: function (e) {
          1 == e.flag
            ? (a.setData(t({ INIT: e.INIT }, "LIST[0]", e.LIST)), a.scrolltop())
            : wx.showToast({ title: e.msg, icon: "none", mask: !0 }),
            wx.hideLoading(),
            (n = !0);
        },
      });
  },
  chk_flag: function () {
    var t = this;
    e.ajax({
      url: "chat.php",
      data: { submitok: "chk_flag", uid: t.data.uid, openid: i.openid },
      success: function (a) {
        1 == a.flag && t.getmess_one();
      },
    });
  },
  onUnload: function () {
    clearInterval(this.time);
  },
  getmess_one: function () {
    var a = this;
    e.ajax({
      url: "chat.php",
      data: { submitok: "getmess_one", uid: a.data.uid, openid: i.openid },
      success: function (e) {
        if (1 == e.flag) {
          var i = a.data.LIST,
            s = i.length - 1,
            n = i[s];
          (n = n.concat(e.LIST)),
            a.setData(t({}, "LIST[" + s + "]", n)),
            a.scrolltop();
        } else wx.showToast({ title: e.msg, icon: "none", mask: !0 });
      },
    });
  },
  moreFn: function () {
    var t = this,
      a = this;
    0 != this.data.INIT.ifmore
      ? (wx.vibrateShort({ type: "heavy" }),
        setTimeout(function () {
          var o = t.data.LIST;
          n
            ? ((n = !1),
              e.ajax({
                url: "chat.php",
                data: {
                  submitok: "more",
                  p: s,
                  uid: a.data.uid,
                  openid: i.openid,
                },
                success: function (t) {
                  if (1 == t.flag) {
                    o.length;
                    if (t.LIST.length < 1)
                      return (n = !1), void a.setData({ triggered: !1 });
                    var e = [];
                    e.push(t.LIST),
                      (e = e.concat(o)),
                      a.setData({ triggered: !1, INIT: t.INIT, LIST: e }),
                      (s += 1),
                      (n = !0);
                  } else wx.showToast({ title: t.msg, icon: "none", mask: !0 });
                },
              }))
            : a.setData({ triggered: !1 });
        }, 500))
      : a.setData({ triggered: !1 });
  },
  sendFn: function (t) {
    var e = t.detail.value.content;
    a.empty(e)
      ? this.setData({ inputfocus: !0 })
      : (this.setData({ inputvalue: e }), this.sendmsg(e));
  },
  sendmsg: function (s) {
    var n = this;
    e.ajax({
      url: "chat.php",
      data: { submitok: "add", uid: n.data.uid, openid: i.openid, content: s },
      success: function (e) {
        if (1 == e.flag) {
          var i,
            o = n.data.LIST,
            c = o.length - 1,
            u = o[c];
          u.push({ class: "my", c: s }),
            n.setData(
              (t((i = {}), "INIT.total", n.data.INIT.total + 1),
              t(i, "LIST[" + c + "]", u),
              t(i, "inputvalue", ""),
              i)
            ),
            n.scrolltop();
        } else (e.this = n), a.sorry(e), n.setData({ div_vip_c: e.msg });
      },
    });
  },
  clicklovebFn: function () {
    var s = this;
    e.ajax({
      url: "chat.php",
      data: { submitok: "clickloveb", uid: s.data.uid, openid: i.openid },
      success: function (e) {
        1 == e.flag
          ? (s.setData(t({ div_clickloveb_confirm: !1 }, "INIT.iflocked", 1)),
            a.empty(s.data.inputvalue) || s.sendmsg(s.data.inputvalue))
          : ((e.this = s),
            a.sorry(e),
            s.setData({ div_data_c: e.msg }),
            "noloveb" == e.flag && s.setData({ div_clickloveb_confirm: !1 }));
      },
    });
  },
  look_lockopenFn: function () {
    var t = this;
    e.ajax({
      url: "chat.php",
      data: { submitok: "look_lockopen", uid: t.data.uid, openid: i.openid },
      success: function (e) {
        1 == e.flag ||
          ((e.this = t),
          a.sorry(e),
          t.setData({ div_data_c: e.msg }),
          "noloveb" == e.flag && t.setData({ div_clickloveb_confirm: !1 }));
      },
    });
  },
  bindconfirmFn: function (t) {
    var e = t.detail.value;
    a.empty(e) || this.sendmsg(e);
  },
  scrolltop: function () {
    var t = this;
    setTimeout(function () {
      t.setData({ scrolltop: 99999 });
    }, 100);
  },
  mask_closeFn: function (a) {
    var e = this,
      i = a.currentTarget.dataset.maskid;
    "back" == a.currentTarget.dataset.closekind &&
      (this.setData(t({}, i, !1)), wx.navigateBack()),
      this.setData({ mask_class: "alpha100_0" }),
      setTimeout(function () {
        e.setData(t({}, i, !1));
      }, 400);
  },
  extFn: function () {
    var t = this;
    e.ajax({
      url: "chat.php",
      data: { submitok: "ext_text", uid: this.uid, openid: i.openid },
      success: function (a) {
        1 == a.flag
          ? t.setData({
              ext_text: a.ext_text,
              ext_show: !0,
              ext_class: "alpha0_100",
            })
          : wx.showToast({ title: a.msg, icon: "none", mask: !0 });
      },
    });
  },
  text_resetFn: function () {
    var t = this;
    e.ajax({
      url: "chat.php",
      data: { submitok: "ext_text", uid: this.uid, openid: i.openid },
      success: function (a) {
        1 == a.flag
          ? t.setData({ ext_text: a.ext_text })
          : wx.showToast({ title: a.msg, icon: "none", mask: !0 });
      },
    });
  },
  text_okFn: function (t) {
    var a = t.currentTarget.dataset.v;
    this.ext_closeFn(), this.setData({ inputvalue: a });
  },
  ext_closeFn: function () {
    var t = this;
    this.setData({ ext_class: "alpha100_0" }),
      setTimeout(function () {
        t.setData({ ext_show: !1 });
      }, 500);
  },
  emptyFn: function () {},
});
